package com.rw.map.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.rw.map.model.HeatMapQueryParam;
import com.rw.map.model.HistoryQueryParam;
import com.rw.map.model.NavigateVO;
import com.rw.map.model.Point;
import com.rw.map.model.Result;
import com.rw.map.model.ResultDataVO;
import com.rw.map.model.ShopFlowQueryParam;
import com.rw.map.service.NavigateService;

/**
 * 
 * @author forest
 *
 */
@RestController
@RequestMapping("/api/navigate")
public class NavigateController {

	@Autowired
	private NavigateService navigateService;
	
	@GetMapping(value = "/test")
	public Result test() {
		return Result.success();
	}
	
	
	/**
	 * 初始化数据接口
	 * @param floorId
	 * @return
	 */
	@GetMapping(value = {"/init/{floorId}/{uid}/{buildingId}", "/init/{floorId}/{uid}"})
	public Result intNavigate(@PathVariable("floorId")String floorId, @PathVariable("uid")String uid, 
			@PathVariable(name = "buildingId", required = false)String buildingId) {
		//navigateService.saveMonitorData();
		List<NavigateVO> list = navigateService.initNavigate(floorId, uid, buildingId);
		return Result.success(list);
	}
	
	/**
	 * 查询历史接口
	 * 参数格式：{"age":"1,2", "floorId":"0001-0002-0002-000K","date":"2021-10-28", "sex":"1"}
	 * @param p
	 * @return
	 */
	@PostMapping(value = "/history")
	public Result history(@RequestBody @Validated  HistoryQueryParam p){
		ResultDataVO rd = navigateService.historyNavigate(p);
		//navigateService.historyNavigateTest(p)
		return Result.success(rd);
	}
	
	@PostMapping(value = "/heatMap")
	public Result heatMap(@RequestBody @Validated HeatMapQueryParam p) {
		return Result.success(navigateService.heatMapCount(p));
	}
	
	@GetMapping(value = {"/getBuilding/{buildingId}", "/getBuilding"})
	public Result getBuilding(@PathVariable(name = "buildingId", required = false)String buildingId) {
		return Result.success(navigateService.getBuilding(buildingId));
	}
	
	@GetMapping(value = {"/getFloor/{buildingId}", "/getFloor"})
	public Result getFloor(@PathVariable(name = "buildingId", required = false)String buildingId) {
		return Result.success(navigateService.getFloor(buildingId));
	}
	
	@GetMapping(value = "/getPath/{buildingCode}/{floorCode}")
	public String getPath(@PathVariable("buildingCode")String buildingCode, 
			@PathVariable("floorCode")String floorCode) {
		String result = navigateService.getPath(buildingCode, floorCode);
		return result;
	}
	
	@GetMapping(value = "/getPoints/{startId}/{endId}")
	public List<Point> getPoints(@PathVariable("startId")String startId, 
			@PathVariable("endId")String endId){
		return navigateService.getPoints(startId, endId);
	}
	
	@GetMapping(value = "/getShopInfo/{shopCode}")
	public String getShopInfo(@PathVariable("shopCode")String shopCode){
		
		return navigateService.getShopInfo(shopCode);
	}
	
	@PostMapping(value = "/getShopFlow")
	public String getShopFlow(@RequestBody @Validated ShopFlowQueryParam p) {
		return navigateService.getShopFlow(p);
	}
	
}
